﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Xml.Serialization;

namespace AutoTLBB {
    [Serializable]
    public class CharacterModel : INotifyPropertyChanged {
        #region Fields
        private bool m_isRunning = false;
        #endregion Fields
        [XmlIgnore]
        public IntPtr WindowHandle { get; set; }
        [XmlIgnore]
        public int ProcessId { get; set; }
        [XmlIgnore]
        public string ID { get; set; }
        [XmlIgnore]
        public string Name { get; set; }
        [XmlIgnore]
        public int Blood { get; set; }
        [XmlIgnore]
        public int Mana { get; set; }
        [XmlIgnore]
        public int PetNo { get; set; }
        [XmlIgnore]
        public int PetBlood { get; set; }
        [XmlIgnore]
        public bool IsHideGame { get; set; }
        [XmlIgnore]
        public float LocationX { get; set; }
        [XmlIgnore]
        public float LocationY { get; set; }
        [XmlElement]
        public SkillDefine BasicSkill { get; set; }
        [XmlAttribute]
        public UserKey Target { get; set; }
        [XmlElement]
        public SkillDefine Skill1 { get; set; }
        [XmlElement]
        public SkillDefine Skill2 { get; set; }
        [XmlElement]
        public SkillDefine Skill3 { get; set; }
        [XmlElement]
        public SkillDefine Skill4 { get; set; }
        [XmlElement]
        public SkillDefine Skill5 { get; set; }
        [XmlElement]
        public SkillDefine Skill6 { get; set; }
        [XmlElement]
        public SkillDefine Skill7 { get; set; }
        [XmlElement]
        public SkillDefine Skill8 { get; set; }
        [XmlElement]
        public SkillDefine EatingBlood { get; set; }
        [XmlElement]
        public SkillDefine EatingMana { get; set; }
        [XmlElement]
        public SkillDefine PetFeed { get; set; }
        [XmlElement]
        public UserDefine ShutdownGameAfterQuestion { get; set; }
        [XmlElement]
        public UserDefine ShutdownGameWhenBlood { get; set; }
        [XmlElement]
        public UserDefine AlertBlood { get; set; }
        [XmlElement]
        public SkillDefine EatingWhenBloodOfPet { get; set; }
        [XmlElement]
        public UserDefine Radius { get; set; }
        [XmlAttribute]
        public HitStyle HitStyle { get; set; }
        [XmlAttribute]
        public int TimeDelayToAttack {
            get;
            set;
        }
        [XmlIgnore]
        public DateTime TimeAutoHandle { get; set; }
        [XmlIgnore]
        public bool IsRunning {
            get { return m_isRunning; }
            set {
                if (m_isRunning != value) {
                    m_isRunning = value;
                    if (PropertyChanged != null) {
                        PropertyChanged(this, new PropertyChangedEventArgs("IsRunning"));
                    }
                }
            }
        }
        [XmlAttribute]
        public bool ShouldAlert { get; set; }
        [XmlAttribute]
        public bool AutoAttack { get; set; }
        [XmlIgnore]
        public bool IsTarget {
            get {
                return GameUtilities.IsTarget(ProcessId) == 1;
            }
        }
        public CharacterModel() {
            //BasicSkill;
            BasicSkill = new SkillDefine { SkillName = "Tự đánh Skill cơ bản", Value = 0, IsSelected = true, SkillKey = UserKey.F1 };
            Skill1 = new SkillDefine { SkillName = "Skill 1", SkillKey = UserKey.F1 };
            Skill2 = new SkillDefine { SkillName = "Skill 2", SkillKey = UserKey.F2 };
            Skill3 = new SkillDefine { SkillName = "Skill 3", SkillKey = UserKey.F3 };
            Skill4 = new SkillDefine { SkillName = "Skill 4", SkillKey = UserKey.F4 };
            Skill5 = new SkillDefine { SkillName = "Skill 5", SkillKey = UserKey.F5 };
            Skill6 = new SkillDefine { SkillName = "Skill 6", SkillKey = UserKey.F6 };
            Skill7 = new SkillDefine { SkillName = "Skill 7", SkillKey = UserKey.F7 };
            //Skill8 = new SkillDefine { SkillName = "Skill 8" , SkillKey= UserKey.F8};
            EatingBlood = new SkillDefine { SkillName = "Ăn máu khi máu   <", SkillKey = UserKey.F9 };
            EatingMana = new SkillDefine { SkillName = "Ăn mana khi    < ", SkillKey = UserKey.F8 };
            PetFeed = new SkillDefine { SkillName = "Pet ăn khi máu   <", SkillKey = UserKey.F10 };
            AlertBlood = new UserDefine() { Text = "Báo khi máu   <", Value = 1000, IsSelected = true };
            EatingWhenBloodOfPet = new SkillDefine { SkillName = "CCS/CHT khi pet full máu", SkillKey = UserKey.F10, Value = 60 };
            Radius = new UserDefine() { Text = "Tọa độ train:", Value = 10 };
            LocationX = 0; LocationY = 0;
            ShutdownGameAfterQuestion = new UserDefine { Text = "Tắt nếu ko trả lời (s):", Value = 30, IsSelected = true };
            ShutdownGameWhenBlood = new UserDefine { Text = "Tắt khi máu <", Value = 500, IsSelected = true };
            AutoAttack = true;
            TimeDelayToAttack = 5;
            Target = UserKey.F11;
            TimeAutoHandle = DateTime.Now;
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }
    [Serializable]
    public class SkillDefine {
        private int m_delay = 10;
        [XmlAttribute]
        public string SkillName { get; set; }
        /// <summary>
        /// Gets or sets a value indicating whether this instance is selected.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is selected; otherwise, <c>false</c>.
        /// </value>
        [XmlAttribute]
        public bool IsSelected { get; set; }
        /// <summary>
        /// After period time, the skill will be action again
        /// </summary>
        /// <value>
        /// The delay.
        /// </value>
        [XmlAttribute]
        public int Value { get { return m_delay; } set { m_delay = value; } }
        /// <summary>
        /// Gets or sets the skill key.
        /// </summary>
        /// <value>
        /// The skill key.
        /// </value>
        [XmlAttribute]
        public UserKey SkillKey { get; set; }
        /// <summary>
        /// Gets a value indicating whether this instance can handle.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance can handle; otherwise, <c>false</c>.
        /// </value>
        [XmlIgnore]
        public bool CanHandle {
            get {
                if ((DateTime.Now - TimeHandle).TotalSeconds > Value) {
                    TimeHandle = DateTime.Now;
                    return true;
                }
                return false;
            }
        }
        /// <summary>
        /// Gets or sets the time handle.
        /// </summary>
        /// <value>
        /// The time handle.
        /// </value>
        [XmlIgnore]
        protected DateTime TimeHandle { get; set; }
        public SkillDefine() {
            TimeHandle = DateTime.Now;
        }
    }
    [Serializable]
    public class UserDefine {
        [XmlAttribute]
        public string Text { get; set; }
        [XmlAttribute]
        public int Value { get; set; }
        [XmlAttribute]
        public bool IsSelected { get; set; }
        [XmlAttribute]
        public UserKey EatingKey { get; set; }
        public UserDefine() {

        }
    }
    [Serializable]
    public enum HitStyle {
        Noi, Ngoai, ByMonster
    }
}
